//
//  KFDInvestmentCommunityManager.m
//  
//
//  Created by JIRENTIANXIANG on 6/28/15.
//
//

#import "KFDInvestmentCommunityManager.h"

@implementation KFDInvestmentCommunityManager

+(KFDInvestmentCommunityManager*)sharedManager
{
    static KFDInvestmentCommunityManager* _manager=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _manager=[[KFDInvestmentCommunityManager alloc] init];
    });
    return _manager;
}

-(NSURLSessionTask*)uploadPicture:(UIImage *)picture successHandler:(KFDUploadInvestmentCommunityPostPictureSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler
{
    KFDClient* client=[KFDClient sharedClient];
    return [client uploadInvestmentCommunityPostPicture:picture successHandler:successHandler failureHandler:failureHandler];
}

-(NSURLSessionTask*)publishPostWithContent:(NSString *)content pictures:(NSArray*)pictures successHandler:(KFDPublishPostSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler
{
    KFDClient* client=[KFDClient sharedClient];
    return [client publishInvestmentCommunityPostWithContent:content pictures:pictures successHandler:successHandler failureHandler:failureHandler];
}

-(NSURLSessionTask*)praisePost:(NSString *)postId successHandler:(KFDPraiseInvestmentCommunityPostSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler
{
    KFDClient* client=[KFDClient sharedClient];
    return [client praiseInvestmentCommunityPost:postId successHandler:successHandler failureHandler:failureHandler];
}

-(NSURLSessionTask*)cancelPraisePost:(NSString *)postId successHandler:(KFDCancelPraiseInvestmentCommunityPostSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler
{
    KFDClient* client=[KFDClient sharedClient];
    return [client cancelPraiseInvestmentCommunityPost:postId successHandler:successHandler failureHandler:failureHandler];
}

-(NSURLSessionTask*)commentPost:(NSString *)postId userId:(NSString *)userId content:(NSString *)content successHandler:(KFDCommentICPostSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler
{
    KFDClient* client=[KFDClient sharedClient];
    return [client commentICPost:postId userId:userId content:content successHandler:successHandler failureHandler:failureHandler];
}

@end

//------------------------------------------------------------------------

@implementation KFDInvestmentCommunityManager (BusinessRules)

-(BOOL)checkContent:(NSString *)content illegalInputHandler:(KFDICManagerIllegalInputHandler)handler
{
    if (content&&content.length>0) {
        return YES;
    }else{
        handler(@"请输入这一刻的想法");
    }
    return NO;
}

-(BOOL)checkComment:(NSString *)comment illegalInputHandler:(KFDICManagerIllegalInputHandler)handler
{
    if (comment&&comment.length>0) {
        return YES;
    }else{
        handler(@"请输入");
    }
    return NO;
}

@end